package xyz.fivefaith.tool.boot.validate;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;


/**
 * 自定义xss校验注解实现
 *
 * @author Lion Li
 */
public class XssValidator implements ConstraintValidator<Xss, String> {

    private static final Pattern HTML_TAG =
            Pattern.compile("(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)");

    @Override
    public boolean isValid(String content, ConstraintValidatorContext constraintValidatorContext) {
        return null == content || !HTML_TAG.matcher(content).find();
    }
}
